package com.waldo.user.controller;

import com.waldo.user.thrift.ServiceProvider;
import org.apache.thrift.TException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Auther: yelo
 * @Date: 2018/10/16 15:51
 * @Description:
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    ServiceProvider serviceProvider;
    @RequestMapping(value = "/msg",method = RequestMethod.GET)
    public String message(){
        return "message";
    }

    @RequestMapping(value="/sendMsg",method = RequestMethod.POST)
    @ResponseBody
    public  String sendMsg(
              @RequestParam("to")String to,@RequestParam("msg") String msg            ){
        try {
            serviceProvider.getMessageService().send_sendMessage(to,msg,"email");
        } catch (TException e) {
            e.printStackTrace();
            return "0";
        }
        return "1";
    }

    @RequestMapping(value="/info",method = RequestMethod.GET)
    @ResponseBody
    public  boolean info(){
        try {
            return serviceProvider.getUserService().insertUser(1,"xxxxxxxxxxxxxx",3);
        } catch (TException e) {
            e.printStackTrace();
            return false;
        }
    }
}
